def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
        return True
def closest_prime_number(num):
    if not num.isdigit() or len(num) != 3:
        return "Wrong input"
    num = int(num)
    lower_num = num - 1
    upper_num = num + 1
    while not is_prime(lower_num) and is_prime(upper_num):
        lower_num -= 1
        upper_num += 1
    if(is_prime(lower_num)):
        return lower_num
    else:
        return upper_num
words = input().split()
num = ""
for word in words:
    if word.lower() == "zero":
        num += "0"
    elif word.lower() == "one":
        num += "1"
    elif word.lower() == "two":
        num += "2"
    elif word.lower() == "three":
        num += "3"
    elif word.lower() == "four":
        num += "4"
    elif word.lower() == "five":
        num += "5"
    elif word.lower() == "six":
        num += "6"
    elif word.lower() == "seven":
        num += "7"
    elif word.lower() == "eight":
        num += "8"
    elif word.lower() == "nine":
        num += "9"
result = closest_prime_number(num)
print(result)
